var uname = localStorage.getItem("uname");
var uid = localStorage.getItem("uid")
function log(operation){
    $.ajax({
        url : "/curriculum/intermediate/addOperationLog",
        dataType : 'json',
        type : 'post',
        data :{"logUserId":uid,"logList":"课程审核","logOperation":operation},
        success : function(res) {

        },
        errorfun : function() {

        }
    });
}
$("#chongzhi").click(function (){
    location.reload();
})
function refresh(){
    tableIn.reload("curriculum");
}
layui.use(['table','form'], function(){
    table = layui.table;
    form = layui.form;
    //第一个实例
    tableIn = table.render({
        elem: '#demo'
        ,id:"curriculum"
        ,height: 600
        ,url: '/curriculum/primary/getAllCm' //数据接口
        ,page: true //开启分页
        ,cols: [[ //表头
            {field: 'curriculumId', title: '编号',  sort: true, fixed: 'left'}
            ,{field: 'curriculumPictureurl', title: '商品图片', width:135,height: 100,
                templet:function (d) { return '<div><img src="'+d.curriculumPictureurl+'", ' +
                    'style="width: 200px;height: 100px"></div>'}}
            ,{field: 'curriculumName', title: '课程名称'}
            ,{field: 'curriculumOriginalPrice', title: '价格'}
            ,{field: 'classificationName', title: '分类'}
            ,{field: 'curriculumToExamine', title: '审核状态',templet: function (d) {
                    if (d.curriculumToExamine == 0){
                        return "未审核"
                    }else if(d.curriculumToExamine == 1) {
                        return "已审核"
                    }else if(d.curriculumToExamine == 2) {
                        return "未通过"
                    }
                }},
            {fixed: 'right',title: '操作', align:'center', toolbar: '#toolDemo'}
        ]],toolbar: '#toolbarDemo'
    });
    table.on('tool(test)', function(obj){
        console.log(obj.data.curriculumName)
        switch(obj.event){
            case 'see':

                layer.open({
                    type:2,
                    title:'查看详情信息',
                    content: "../../../pages/course/courseManagement/enrymsg/viewDetails.html",
                    area:['80%','80%'],
                    success:function(layero,index) {
                        var boby = layer.getChildFrame('body,index');
                        boby.find("td[name = curriculumName]").text(obj.data.curriculumName);
                        boby.find("td[name = currculumCreationTime]").text(obj.data.currculumCreationTime);
                        boby.find("td[name = currculumCreatedBy]").text(obj.data.currculumCreatedBy);
                        boby.find("td[name = curriculumOriginalPrice]").text(obj.data.curriculumOriginalPrice);
                        boby.find("td[name = curriculumKeyWord]").text(obj.data.curriculumKeyWord);
                        boby.find("td[name = classificationName]").text(obj.data.classificationName);
                        boby.find("td[name = currculumLikes]").text(obj.data.currculumLikes);
                        boby.find("td[name = currculumCollectionQuantity]").text(obj.data.currculumCollectionQuantity);
                        boby.find("td[name = currculumCommentVolume]").text(obj.data.currculumCommentVolume);
                        boby.find("td[name = curriculumSynopsis]").text(obj.data.curriculumSynopsis);
                        boby.find("td[name = curriculumPictureurl]").html('<div><img src="'+obj.data.curriculumPictureurl+'", ' +
                            'style="width: 200px;height: 100px"></div>');
                        boby.find("td[name = curriculumUrl]").html('<div><video src="'+obj.data.curriculumUrl+'"style="width: 800px;height: 600px" controls></video> </div>');


                    }
                })
                log("查看")
                break;
            case 'edit':
                layer.open({
                    type:2,
                    title:'审核',
                    content: "../../../pages/course/courseManagement/enrymsg/auditDetails.html",
                    shade: 0,
                    area:['30%','50%'],
                    success:function(layero,index) {
                        var boby = layer.getChildFrame('body,index');
                        boby.find("#curriculumName").html(obj.data.curriculumName);
                        boby.find("input[name=curriculumId]").attr("value",obj.data.curriculumId);
                        boby.find("input[name=uname]").attr("value",uname);
                    }
                })
                break;

        };
    });


});
function dropdw(){
    var data
    $.ajax({
        url : "/curriculum/primary/getAllDropDownBox",
        dataType : 'json',
        async:false,
        type : 'get',
        data :[],
        success : function(res) {
            data = res.data;
            console.log(data);
        }
    })
    return data;
}
layui.use('dropdown', function(){
    var dropdown = layui.dropdown
    let dropdw1 = dropdw();



    dropdown.render({
        elem: '#demo1' //可绑定在任意元素中，此处以上述按钮为例
        ,data: dropdw1
        ,id: 'demo1'
        //菜单被点击的事件
        ,click: function(obj){

            curriculumClassificationid = obj.id
            table.reload('curriculum',{

                where:{
                    curriculumClassificationid:curriculumClassificationid
                }
            })
        }
    });
});
$("input[name='curriculumOriginalPrice']").blur(function () {
    var val = $(this).val();
    curriculumOriginalPrice1 = val
    table.reload('curriculum',{

        where:{
            curriculumOriginalPrice:val
        }
    })
});
$("input[name='curriculumName']").blur(function () {

    var val = $(this).val();
    curriculumName1 = val;
    table.reload('curriculum',{

        where:{
            curriculumName:val
        }
    })
});
$("#advancedQuery").click(function (){
    layer.open({
        type: 2,
        content: '../../../pages/course/courseManagement/enrymsg/advancedQuery.html',
        title:"高级搜索",
        area: ['50%', '50%']
    });
})
function abvancedQuery(data){
    table.reload('curriculum',{

        where:{
            curriculumName:data.curriculumName,
            curriculumOriginalPrice:data.curriculumOriginalPrice,
            curriculumClassificationid:data.curriculumClassificationid,
            curriculumShelves:data.curriculumShelves,
            curriculumToExamine:data.curriculumToExamine,
            currculumCreatedBy:data.currculumCreatedBy
        }
    })
    log("高级搜索")
}
var a = 0;
$("#screen").click(function (){
    a++;
    if((a%2) == 1){
        $("#screen").html('<i class="layui-icon layui-icon-up " ></i>收起筛选')
        // '<span style="color: #c00;">'+ d.title +'</span>'
        $("#search").removeClass("dipy");
    }else if ((a%2) == 0){
        $("#screen").html('<i class="layui-icon layui-icon-down " ></i>展开筛选')
        $("#search").addClass("dipy");
    }
})